<?php
// +----------------------------------------------------------------------
// | Behavior 类型服务
// +----------------------------------------------------------------------
// | Behavior 过程中所需的通用处理方法
// +----------------------------------------------------------------------
// | 错误编码头 242xxx
// +----------------------------------------------------------------------

namespace common\service;

use support\SingletonTrait;

class BehaviorService
{
    use SingletonTrait;

    /**
     * 通用预处理方法，包含键值判断
     * @param $param
     * @param $structure
     * @param $defaultParam
     * @param $dataKey
     * @param $judge
     * @return array|false
     */
    public function dealParam($param, $structure, $defaultParam = [], $dataKey = '', $judge = [])
    {
        foreach ($judge as $key => $val) {
            if (!isset($param[$key]) || $param[$key] != $val) {
                return false;
            }
        }
        if (!empty($dataKey)) {
            $param = $param[$dataKey];
        }
        return array_values(query_array_construct($structure, $param, $defaultParam));
    }
}
